package io.renren.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.base.AntInfo;
import io.renren.service.WebAntManagerService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;

/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-07-18 14:56:39
 * 爬虫管理列表
 */
@RestController
@RequestMapping("webantmanager")
public class WebAntManagerController {
    
    @Autowired
    private WebAntManagerService webAntManager;
    
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("webantmanager:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<AntInfo> antInfos = webAntManager.queryList(query);
        int total = webAntManager.queryTotal(query);
        
        PageUtils pageUtil = new PageUtils(antInfos, total, query.getLimit(), query.getPage());
        
        return R.ok().put("page", pageUtil);
    }
    
    /**
     * 启动
     */
    @RequestMapping("/start")
    public R start(@RequestBody String[] ids){
        webAntManager.start(ids);
        return R.ok();
    }
    /**
     * 停止
     */
    @RequestMapping("/stop")
    public R stop(@RequestBody String[] ids){
        webAntManager.stop(ids);
        return R.ok();
    }
}
